/* global Vue */
import { isNull } from 'utils/ui-utils'
import * as actionTypes from './mutation-types'

export default {
  [actionTypes.NEED_SHOW_LOGIN_POP](state, value) {
    state.needShowLoginPop = value
  },
  [actionTypes.PAGE_STATUS_INFO](state, payload) {
    let newObj = state.pageStatusInfo
    if (!newObj) {
      newObj = {}
    }
    if (Object.prototype.toString.call(payload) === '[object Object]') {
      Object.keys(payload).forEach(key => {
        if (!isNull(payload[key])) {
          // newObj[key] = payload[key]
          Vue.set(newObj, key, payload[key])
        } else if (newObj.hasOwnProperty(key)) {
          delete newObj[key]
        }
      })
      state.pageStatusInfo = newObj
    }
  },
}
